﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;

namespace YouHP.Pages.WeightHistory
{
    public class Index : YouHP.Pages.PatientBasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        public List<WeightHistoryInfo> WeightHistoryList;
        protected int PageCount;
        protected int PageIndex;
        protected int PageSize = 10;
        protected string PagingString = "";
        protected int DataCount = 0;

        protected WeightHistoryInfo WeightHistoryData;
        protected string WeightGraphPath;
        protected const int WeightGraphHeight = 170;

        protected new void HandleCommon()
        {
            this.AddLocation("体重记录", "");
            this.SetTitle("体重记录");
        }

        protected new void HandlePost()
        {

        }

        protected new void HandleGet()
        {
            WeightGraphPath = GetUrl("/WeightHistory/WeightAjax.aspx");

            //获取历史体重数据
            WeightHistoryData = PatientBLL.Instance.GetCurrentWeight(PrData.Id);
            if (WeightHistoryData.Id <= 0) 
            {
                /*this.AddErrLine("您还没有填写体重信息，请填写!");
                this.SetUrl("/WeightHistory/HistoryAdd.aspx");
                return;*/
                //this.Redirect("/WeightHistory/HistoryAdd.aspx");
            }

            //取得身高
            double height = PatientBLL.Instance.GetPatientHeight(UserData.Id);
            //if (height <= 0 && WeightHistoryData.Id > 0)    //右体重数据,但是没有体重数据
            //{
            //    this.AddErrLine("为方便计算体重指数,请填写身高信息");
            //    this.SetUrl("/WeightHistory/HeightEdit.aspx");
            //    return;
            //}
            WeightHistoryData.Height = height;

            //PageIndex = RequestTools.GetQueryInt("page", 1);
            //WeightHistoryList = PatientBLL.Instance.GetWeightHistoryList(PrData.Id, PageSize, PageIndex, out DataCount);
            //PageCount = Utils.GetPageCount(DataCount, PageSize);

            //string query = HttpContext.Current.Request.Url.Query;
            //query = Utils.RemoveQueryItem(query, "page");

            //PagingString = this.GetPagingString(
            //    PageIndex,
            //    PageCount,
            //    "/WeightHistory/Index.aspx" + query, "page");
        }
    }
}